package com.glsc.ngateway.common.base.repo.mysql.cmdb;

import com.glsc.ngateway.common.base.domain.mysql.cmdb.CmdbMachineRoom;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface CmdbMachineRoomRepository extends JpaRepository<CmdbMachineRoom, Integer>, JpaSpecificationExecutor<CmdbMachineRoom> {
    @Query(value = "select m from CmdbMachineRoom m where m.isDelete=0 " +
//            "and (:#{#paramSearchDto.shareHolderAccount} is null OR m.shareHolderAccount = :#{#paramSearchDto.shareHolderAccount})  " +
//            "and (:#{#paramSearchDto.shareHolderAccountName} is null OR m.shareHolderAccountName = :#{#paramSearchDto.shareHolderAccountName})  " +
            "and (:#{#paramSearchDto.name} is null OR m.name LIKE CONCAT('%', :#{#paramSearchDto.name}, '%')) " +
            "and (:#{#paramSearchDto.address} is null OR m.address LIKE CONCAT('%', :#{#paramSearchDto.address}, '%')) " +
            "and (:#{#paramSearchDto.contactName} is null OR m.contactName LIKE CONCAT('%', :#{#paramSearchDto.contactName}, '%')) " +
            "and (:#{#paramSearchDto.contactAccount} is null OR m.contactAccount LIKE CONCAT('%', :#{#paramSearchDto.contactAccount}, '%')) " +
            "and (:#{#paramSearchDto.contactPhone} is null OR m.contactPhone LIKE CONCAT('%', :#{#paramSearchDto.contactPhone}, '%')) " +
            "and (:#{#paramSearchDto.cabinetAmount} is null OR m.cabinetAmount = :#{#paramSearchDto.cabinetAmount}) " +
            "and (:#{#paramSearchDto.selfMachineRoomLevel} is null OR m.selfMachineRoomLevel LIKE CONCAT('%', :#{#paramSearchDto.selfMachineRoomLevel}, '%')) " +
            "and (:#{#paramSearchDto.selfMachineRoomType} is null OR m.selfMachineRoomType = :#{#paramSearchDto.selfMachineRoomType}) " +
            "and (:#{#paramSearchDto.isFireRecord} is null OR m.isFireRecord = :#{#paramSearchDto.isFireRecord}) " +
            "and (:#{#paramSearchDto.isFireCheck} is null OR m.isFireCheck = :#{#paramSearchDto.isFireCheck}) " +
            "and (:#{#paramSearchDto.fireType} is null OR m.fireType LIKE CONCAT('%', :#{#paramSearchDto.fireType}, '%')) " +
            "and (:#{#paramSearchDto.electricityType} is null OR m.electricityType LIKE CONCAT('%', :#{#paramSearchDto.electricityType}, '%')) " +
            "and (:#{#paramSearchDto.area} is null OR m.area = :#{#paramSearchDto.area}) " +
            "and (:#{#paramSearchDto.upsTotalPower} is null OR m.upsTotalPower = :#{#paramSearchDto.upsTotalPower}) " +
            "and (:#{#paramSearchDto.upsMiniRunTime} is null OR m.upsMiniRunTime = :#{#paramSearchDto.upsMiniRunTime}) " +
            "and (:#{#paramSearchDto.upsAvgLoad} is null OR m.upsAvgLoad = :#{#paramSearchDto.upsAvgLoad}) " +
            "and (:#{#paramSearchDto.buildSupportEletricityVehicle} is null OR m.buildSupportEletricityVehicle = :#{#paramSearchDto.buildSupportEletricityVehicle}) " +
            "and (:#{#paramSearchDto.totalPower} is null OR m.totalPower = :#{#paramSearchDto.totalPower}) " +
            "and (:#{#paramSearchDto.currentPowerUseage} is null OR m.currentPowerUseage = :#{#paramSearchDto.currentPowerUseage}) " +
            "and (:#{#paramSearchDto.eleGeneratorSupportType} is null OR m.eleGeneratorSupportType LIKE CONCAT('%', :#{#paramSearchDto.eleGeneratorSupportType}, '%')) " +
            "and (:#{#paramSearchDto.eleGeneratorTotalPower} is null OR m.eleGeneratorTotalPower = :#{#paramSearchDto.eleGeneratorTotalPower}) " +
            "and (:#{#paramSearchDto.eleGeneratorOilSupportTime} is null OR m.eleGeneratorOilSupportTime = :#{#paramSearchDto.eleGeneratorOilSupportTime}) " +
            "and (:#{#paramSearchDto.eleGeneratorStartTime} is null OR m.eleGeneratorStartTime = :#{#paramSearchDto.eleGeneratorStartTime}) " +
            "and (:#{#paramSearchDto.airConditionTotalPower} is null OR m.airConditionTotalPower = :#{#paramSearchDto.airConditionTotalPower}) " +
            "and (:#{#paramSearchDto.machineRoomCode} is null OR m.machineRoomCode LIKE CONCAT('%', :#{#paramSearchDto.machineRoomCode}, '%')) " +
//            "and (:#{#paramSearchDto.shareHolderAccountName} is null OR m.shareHolderAccountName LIKE CONCAT('%',:#{#paramSearchDto.shareHolderAccountName},'%') )  " +
//            "and (:#{#paramSearchDto.market} is null OR m.market = :#{#paramSearchDto.market})  " +
//            "and (:#{#paramSearchDto.status} is null OR m.status = :#{#paramSearchDto.status})  " +
//            "and (:#{#paramSearchDto.shareHolderUseDepartment} is null OR m.shareHolderUseDepartment = :#{#paramSearchDto.shareHolderUseDepartment})  " +
//            "and (:#{#paramSearchDto.belongDeptId} is null OR m.belongDeptId = :#{#paramSearchDto.belongDeptId})  " +
//            "and (:#{#paramSearchDto.opSupportName} is null OR m.opSupportName LIKE CONCAT('%',:#{#paramSearchDto.opSupportName},'%') )  " +
//            "and (:#{#paramSearchDto.systemSummary} is null OR m.systemSummary LIKE CONCAT('%',:#{#paramSearchDto.systemSummary},'%') )  " +
//            "and (:#{#paramSearchDto.processDefineKey} is null OR m.processDefineKey = :#{#paramSearchDto.processDefineKey} )  " +
//            "and (:#{#paramSearchDto.systemCode} is null OR m.systemCode = :#{#paramSearchDto.systemCode} )  " +
//            "and (:#{#paramSearchDto.beginDateLocalDate} is null OR m.processCreateTime >= :#{#paramSearchDto.beginDateLocalDate} )  " +
//            "and (:#{#paramSearchDto.endDateLocalDate} is null OR m.processCreateTime <= :#{#paramSearchDto.endDateLocalDate} )  " +
//            "and (:#{#paramSearchDto.hasProcessEnd} is null OR m.isClose = :#{#paramSearchDto.hasProcessEnd} )  " +
//            "and (coalesce(:#{#paramSearchDto.adminList}, null) is null or m.systemAdminAccount in (:#{#paramSearchDto.adminList})) " +
            "")
    Page<CmdbMachineRoom> searchByParam(Pageable pageable, CmdbMachineRoom paramSearchDto);

    List<CmdbMachineRoom> findAllByIdIn(List<Long> id);

    @Transactional
    @Modifying
    @Query(value = "update t_cmdb_machine_room set is_delete = :deleted where machine_room_code in :codes ", nativeQuery = true)
    void updateIsDeleteByCodes(Integer deleted, List<String> codes);

    List<CmdbMachineRoom> findAllByIsDelete(Integer noDelete);
}



